package ge.modules.drawables;

import ge.engine.Log;
import ge.engine.Positionable;
import ge.exceptions.FunctionNonSuported;
import ge.lowlevel.DrawEngine;
import ge.modules.Module;

/**
 * 
 * @author Abel
 *	Prints a text in the screen
 */
public class TextModule implements Module, ILayer, Positionable
{

	private String text;
	private double X;
	private double Y;
	private String font;
	private int layer;
	private Color c;
	private boolean visible;
	/**
	 * 	Constructor of Text Module
	 * @param text String with the text, if it's "" it won't show any text;
	 * @param font For example "bold 14px san-serf", which is the default one
	 */
	public TextModule(String text, String font)
	{
		this.text = text;
		this.X = 0;
		this.Y = 0;
		this.font = "bold 14px  sans-serif";
		c = new Color();
		if(font != "")
			this.font = font;
		layer = 0;
		visible =  true;
	}
	
	/**
	 * 
	 * @return The color of the text
	 */
	public Color getColor() {
		return c;
	}

    /**
     * 
     * @param c Changes the color of the text.
     */
	public void setColor(Color c)
	{
		this.c = c;
	}


	/**
	 * Constructor of Text Module
	 * The font is the defualt's one.
	 * @param text String with the text, if it's "" it won't show any text;
	 * 
	 */
	public TextModule(String text)
	{
		this.text = text;
		this.X = 0;
		this.Y = 0;
		this.font = "bold 14px sans-serif";
		c = new Color();
		visible = true;
	}
	
	@Override
	public void update() 
	{
	
	}

	@Override
	public void draw() 
	{
		 
		if(!visible)
			return;
		
		if(text != "")
		{
			try 
			{
				DrawEngine.get().setLayer(layer);
				if(!c.isBlack())
					DrawEngine.get().setColor(c.getR(), c.getG(), c.getB(),c.getA());
				
				DrawEngine.get().drawText(text, X, Y, font);
				
				if(!c.isBlack())
					DrawEngine.get().setColor(0,0,0);
				
			} catch (FunctionNonSuported e) {
				e.printStackTrace();
			}
		}
	}
	/**
	 * Makes visible or invisible the text
	 * @param visible
	 */
	public void setVisible(boolean visible)
	{
		this.visible = visible;
	}
	/**
	 * 
	 * @return If is visible now  or not
	 */
	public boolean getVisible()
	{
		return  visible;
	}
	public String getText() {
		return text;
	}
	/**
	 * 	
	 * @param text Sets that text
	 */
	public void setText(String text) {
		this.text = text;
	}
	/**
	 * Concatenates that text at the text module 
	 * @param text Text to be concatenated
	 */
	public void add(String text)
	{
		this.text+=text;
	}
	public void setPos(double x, double y) {
		X = x;
		Y = y;
	}
	public double getX() {
		return X;
	}
	public double getY() {
		return Y;
	}
	public String getFont() {
		return font;
	}
	/**
	 * 
	 * @param font If its "" it will use a default font style.
	 */
	public void setFont(String font) {
		this.font = font;
	}

	@Override
	public void delete() {
		this.text ="";
		
	}

	@Override
	public void setLayer(int layer) {
		this.layer = layer;
		
	}

	@Override
	public int getLayer() {
		return layer;
	}
	
	

}
